﻿package com.badibadi.adapter;

import java.util.ArrayList;
import java.util.List;

import net.tsz.afinal.FinalBitmap;

import com.badibadi.infos.User_Club;
import com.badibadi.mytools.Constants;
import com.badibadi.mytools.DisplayUtil;
import com.badibadi.mytools.IOUtils;
import com.badibadi.mytools.ViewHolder;
import com.badibadi.uniclubber.R;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

public class ManageClubAdapter extends BaseAdapter {


	private Context context;

	private static int ImageWH=55;
	FinalBitmap finalBitmap;
	private List<User_Club> mlist;
	public ManageClubAdapter(Context ct,List<User_Club> list) {
		// TODO Auto-generated constructor stub
	
		context = ct;
		finalBitmap=FinalBitmap.create(context);
		  //磁盘缓存路径
        finalBitmap.configDiskCachePath(IOUtils.getSaveObjectPath(context, "ManageClubAdapter"));
        finalBitmap.configDiskCacheSize(10*1024);
		mlist=list;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return mlist.size()-1;
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return mlist.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		 if (convertView == null) {  
             convertView = ViewHolder.buildView(context,R.layout.manage_club_child_layout1, parent);  
         }  
         ViewHolder viewHolder = (ViewHolder) convertView.getTag();  
      // 俱乐部名称
         TextView clubName = viewHolder.getViewById(R.id.manage_club_clubname);  
         clubName.setText("" + mlist.get(position).getName());  
		
         TextView memberNumber=viewHolder.getViewById(R.id.manage_club_member_number);
         memberNumber.setText("" + mlist.get(position).getAddnum());
         
         ImageView headImg=viewHolder.getViewById(R.id.manage_club_club_head_img);
//         headImg.setImageResource(ClubHeadImg[position]);
         
   try {
       finalBitmap.display(headImg, Constants.BadiDownImgUrl+"/"+mlist.get(position).getLogo()+Constants.Appactivitycover,DisplayUtil.dip2px(context, ImageWH),DisplayUtil.dip2px(context, ImageWH));
   } catch (Exception e) {
	// TODO: handle exception
}         
		return convertView;
	}
//	//把组装xml view的 函数抽取出来  
//    protected View buildView(Context context,int redId, ViewGroup parent) {  
//        View view = LayoutInflater.from(context).inflate(redId, parent, false);  
//        view.setTag(new ViewHolder(view));  
//        return view;
//    }  
	

}
